﻿using System;
using System.ComponentModel;
using System.Linq;
using System.Windows.Media;

namespace NyanBankIntfTool
{
    class OldLogger : INotifyPropertyChanged
    {
        private string logText;
        public event PropertyChangedEventHandler PropertyChanged;
        private static OldLogger oldLogger;
        private readonly string[] levels;

        private OldLogger()
        {
            levels = new string[] { "错误", "提示", "信息", "调试" };
            logText = "";
        }
        public string LogText
        {
            get
            {
                return logText;
            }
            set
            {
                logText = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("LogText"));
                }
            }
        }

        public void Log(string text, LogLevel level = LogLevel.Info)
        {
            if (logText.Length > 10000)
            {
                logText = logText.Remove(0, 5000);
            }
            if (level != LogLevel.Output)
            {
                LogText += $"{DateTime.Now}: [{levels[(int)level]}]{text}\n";
            }
            else
            {
                LogText += $"{text}\n";
            }

        }

        public static OldLogger GetInstance()
        {
            if (oldLogger == null)
            {
                oldLogger = new OldLogger();
            }
            return oldLogger;
        }
    }


}
